<?php

class debug_ip_m_core extends a_base_model {

    public function __construct() {
        parent::__construct();
    }

    public function insert_debug_ip($ip,$ignore_maintenance=TRUE, $smarty_console=TRUE, $debug_print=TRUE) {
        $data = array(
            'ip_address' => $ip,
            'debug_print_on' => $debug_print ? 1 : 0,
            'smarty_console_on' => $smarty_console ? 1 : 0,
            'ignore_maintenance'=>$ignore_maintenance ? 1: 0
        );

        $this->db()->insert('debug_ips', $data);
        return $this->db()->affected_rows()>0 ? TRUE : FALSE;
    }

    public function remove_debug_ip($ip) {
        $this->db()->query("DELETE FROM debug_ips WHERE ip_address='$ip'");
        return $this->db()->affected_rows() > 0 ? TRUE : FALSE;
    }

    public function is_ignore_maintenance($ip){
        $query = $this->db()->query("SELECT * FROM debug_ips WHERE ip_address='$ip' AND ignore_maintenance=1 LIMIT 1 ");
        return $query->num_rows() > 0 ? TRUE : FALSE;
    }

    public function is_debug_print_on($ip) {
        $query = $this->db()->query("SELECT * FROM debug_ips WHERE ip_address='$ip' AND debug_print_on=1 LIMIT 1 ");
        return $query->num_rows() > 0 ? TRUE : FALSE;
    }

    public function is_smarty_console_on($ip) {
        $query = $this->db()->query("SELECT * FROM debug_ips WHERE ip_address='$ip' AND smarty_console_on=1 LIMIT 1 ");
        return $query->num_rows() > 0 ? TRUE : FALSE;
    }

    public function valid_debug_ip($ip) {
        $query = $this->db()->query("SELECT * FROM debug_ips WHERE ip_address='$ip'");
        return $query->num_rows() > 0 ? TRUE : FALSE;
    }

    public function set_smarty_console($ip,$flag) {
        $this->db()
                ->set('smarty_console_on',$flag)
                ->where("ip_address",$ip)
                ->update("debug_ips");

    }

    public function set_debug_print($ip,$flag) {
        $this->db()
                ->set('debug_on',$flag)
                ->where("ip_address",$ip)
                ->update("debug_ips");
    }

    public function set_ignore_maintenance($ip,$flag) {
        $this->db()
                ->set('ignore_maintenance',$flag)
                ->where("ip_address",$ip)
                ->update("debug_ips");
    }

}
?>